/*
* berton
*/
package com.pitop.supplier.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

import com.pitop.supplier.api.SupplierCategoryFeignApi;
import com.pitop.core.exceptions.SupplierCategoryException;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.entity.Page;
import com.pitop.supplier.entity.SupplierCategory;


/**
 * 供应商类型
 * @author berton
 */
@Service("supplierCategorySVImpl")
@Slf4j
public class SupplierCategorySVImpl {

    @Autowired
    private SupplierCategoryFeignApi supplierCategoryFeignApi;

    /**
     * 加载一个对象SupplierCategory
     * @param id * @param code 类型编码
     * @return SupplierCategory
     */
    public SupplierCategory load(java.lang.Long id,java.lang.String code) {
        if(id==null&&code==null){
            throw new SupplierCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return supplierCategoryFeignApi.load(id,code);
    }
    /**
     * 加载一个对象SupplierCategory 通过id
     * @param id 
     * @return SupplierCategory
     */
    public SupplierCategory loadById(java.lang.Long id) {
        if(id==null){
            throw new SupplierCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return supplierCategoryFeignApi.loadById(id);
    }

    /**
     * 加载一个对象SupplierCategory 通过code
     * @param code 类型编码
     * @return SupplierCategory
     */
    public SupplierCategory loadByCode(java.lang.String code) {
        if(code==null){
            throw new SupplierCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        return supplierCategoryFeignApi.loadByCode(code);
    }


    /**
     * 删除对象SupplierCategory
     * @param id * @param code 类型编码
     * @return SupplierCategory
     */
    
    public void delete(java.lang.Long id,java.lang.String code) {
        if(id==null&&code==null){
            throw new SupplierCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);
        }
        supplierCategoryFeignApi.delete(id,code);
    }



    /**
     * 查询SupplierCategory分页
     *
     * @param supplierCategory  对象
     * @param curPage 当前页
     * @param pageSize 分页条数
     * @return List<SupplierCategory>
     */
    public List<SupplierCategory> list(SupplierCategory supplierCategory, int curPage,int pageSize) {
        return supplierCategoryFeignApi.list(supplierCategory, curPage,pageSize);
    }

    /**
     * 查询SupplierCategory分页
     *
     * @param id  * @param code  类型编码
     * @param curPage 当前页
     * @param pageSize 分页条数
     * @return List<SupplierCategory>
     */
    public List<SupplierCategory> list(java.lang.Long id,java.lang.String code,int curPage, int pageSize) {
        if (curPage < 0) {
           curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        SupplierCategory supplierCategory=new SupplierCategory();
        supplierCategory.setId(id);
        supplierCategory.setCode(code);

        return supplierCategoryFeignApi.list(supplierCategory,curPage,pageSize);
    }


    public int count(java.lang.Long id,java.lang.String code) {
        return supplierCategoryFeignApi.count(id,code);
    }


    public int count(SupplierCategory supplierCategory) {
        return supplierCategoryFeignApi.count(supplierCategory);
    }


    /**
     * 保存
     *
     * @param supplierCategory 实体
     * @throws BaseException
     */
    public void save(SupplierCategory supplierCategory) {
        if(supplierCategory==null){ throw new SupplierCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);}
        supplierCategoryFeignApi.build(supplierCategory);
    }

    /**
     * 更新
     *
     * @param supplierCategory 实体
     * @throws BaseException
     */
    public void modify(SupplierCategory supplierCategory) {
        if(supplierCategory==null){ throw new SupplierCategoryException(BaseException.BaseExceptionEnum.Ilegal_Param);}
        supplierCategoryFeignApi.modify(supplierCategory);
    }

}
